<?php
namespace app\controller\en;

use think\facade\View;

use app\controller\en\Base;
use app\model\IndustryEn as IndustryModel;

class Industry extends Base
{
    public function index() 
    {
        $list = IndustryModel::field('id, title, titlepic, summary, create_time')->paginate(12);

        View::assign('list', $list);

        return View::fetch();
    }

    public function read($id = 0)
    {
        if ($id == 0) {
            return $this->notFound('Not Found');
        }

        $data = IndustryModel::getOne($id);

        if ($data == null) {
            return $this->notFound("Not Found");
        }

        if ($data->type==1) {
            View::config(['view_path' => $this->app->getRootPath().'view/']);

            return View::display($data->content);
        } else {
            $nextprev = IndustryModel::getNextPrev($id);

            // 覆盖Base seo
            $this->system['title'] = $data->title . '-' . $this->system['title'];
            $this->system['key'] = $data->key . '-,' . $this->system['key'];
            $this->system['des'] = $data->des;

            View::assign('system', $this->system); 

            return View::fetch('', [
                'data'     => $data,
                'nextprev' => $nextprev
            ]);
        }
    }

    /**
     * 单页测试
     */
    public function single($id = 0)
    {
        if ($id == 0) {
            return $this->notFound('单页不存在');
        }

        $html = $this->app->getRootPath() . 'view/en' . DIRECTORY_SEPARATOR . 'industry' . DIRECTORY_SEPARATOR . 'industry' . $id . '.html';

        return View::fetch($html);
    }

}
